<!DOCTYPE html>
<html xmlns="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<base th:href="@{/}" />
<title>Insert title here</title>
<link rel="stylesheet" th:href="@{/css/bootstrap.min.css}"/>
<link rel="stylesheet" th:href="@{/css/Managerstyle.css}"/>
<script th:src="@{/js/jquery-3.4.1.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
</head>
<body>
	<div class="contain">
		<h3>教师管理</h3>
		<table class="table table-hover">
			<tr>
				<td>教职工号</td>
				<td>教职工姓名</td>
				<td>所属院系</td>
				<td>性别</td>
				<td>出生日期</td>
				<td>简介</td>
				<td>邮箱</td>
				<td>操作</td>
			</tr>
			<tr th:each="teacher:${teacherlist}" th:id="|tr${teacher.tid}|">
				<td th:text="${teacher.tid}"></td>
				<td th:text="${teacher.tname}"></td>
				<td th:text="${teacher.acadamy.acdmname}"></td>
				<td th:text="${teacher.tgender}"></td>
				<td th:text="${teacher.birthday}"></td>
				<td th:text="${teacher.description}"></td>
				<td th:text="${teacher.temail}"></td>
				<td>
					<a th:href="|mc/to_modifyTeacher/${teacher.tid}|">编辑</a> 
					<a th:href="|javascript:deleteTeacher(${teacher.tid});|">删除</a>
				</td>
			</tr>
		</table>
		<br>
		
		<!-- Button trigger modal -->
		<button type="button" class="btn btn-success" data-toggle="modal" data-target="#addTeacher">
		  添加新教师
		</button>
		
		<div class="text-center">
			<nav>
				<ul class="pagination">
					<li><a th:href="@{/mc/getAllTeacher/(pageNo=1)}">首页</a></li>
					<li><a th:href="@{/mc/getAllTeacher/(pageNo=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}">上一页</a></li>
					<li th:each="page:${pageInfo.navigatepageNums}">
						<a th:class="${pageInfo.pageNum}==${page}?'active'"
						   th:href="@{/mc/getAllTeacher/(pageNo=${page})}">[[${page}]]</a>
					</li>
					<li><a th:href="@{/mc/getAllTeacher/(pageNo=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}">下一页</a></li>
					<li><a th:href="@{/mc/getAllTeacher/(pageNo=${pageInfo.pages})}">尾页</a></li>
				</ul>
			</nav>
		</div>
		
		<!-- addTeacher -->
		<div class="modal fade" id="addTeacher" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
		    <div class="modal-content">
		      <div class="modal-header">
		        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		        <h4 class="modal-title" id="myModalLabel">添加新教师</h4>
		      </div>
		      <form action="mc/addTeacher" method="post">
		      <div class="modal-body">
					<dl class="dl-horizontal">
					  <dt><label for="tid">教职工号：</label></dt>
					  <dd><input type="text" pattern="[0-9]{8}" required="required" id="tid" name="tid" title="8位数字的教职工号" placeholder="输入8位教职工号" class="form-control"></dd>
					  <br>
					  <dt><label for="tname">教职工姓名：</label></dt>
					  <dd>
					 	  <input type="text" id="tname" name="tname" required="required" placeholder="在此输入教职工姓名" class="form-control">
					  </dd>
					  <br>
					  <dt>所属院系：</dt>
					  <dd>
					 	 <select name="acdmid">
							 <option th:each="acadamy:${acadamylist}" th:value="${acadamy.acdmid}" th:text="|${acadamy.acdmname}|"></option>
						 </select>
					  </dd>
					  <br>
					  <dt>性别：</dt>
					  <dd>
					 	 <select name="tgender" >
							 <option value="男">男</option>
							 <option value="女 ">女</option>
						 </select>
					  </dd>
					  <br>
					  <dt>出生日期：</dt>
					  <dd>
					 	  <input type="date" name="birthday" placeholder="在此输入出生日期" class="form-control">
					  </dd>
					  <br>
					  <dt>简介：</dt>
					  <dd>
					 	  <input type="text" name="description" class="form-control">
					  </dd>
					  <br>
					  <dt>邮箱：</dt>
					  <dd>
					 	  <input type="text" name="temail" class="form-control" >
					  </dd>
					</dl>
		      </div>
		      <div class="modal-footer">
		        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		        <input type="submit" class="btn btn-primary" value="添 加">
		      </div>
		      </form>
		    </div>
		  </div>
		</div>
		
    </div>
    
    <script type="text/javascript">  
            function deleteTeacher(id) {
            	var Tid = id;
                $.ajax({
                    url: 'mc/deleteTeacher',
                    type: 'POST',
                    data: {tid: Tid}, 
                    success: function () {
                    	  $("#tr" + Tid).remove(); 
                    },
                    error: function (req, status, error) {
                        alert("该教师存在课程安排，无法删除");
                    }
                });
            }
    </script>

</body>
</html>